import { request } from "../../request/index.js";
// import regeneratorRuntime from '../../lib/runtime.js';
import { login } from "../../utils/asyncWx.js"
Page({
  //获取用户信息
  async handleGetUserInfo(e) {
    try {
      //1.获取用户信息
      const { encryptedData, iv, rawData, signature } = e.detail;
      //2.获取小程序登录成功之后的code
      const { code } = await login();
      const loginParams = { encryptedData, iv, rawData, signature, code };
      //3.发送请求，获取用户的token
      const token = await request({ url: "/users/wxlogin", data: loginParams, method: "POST" });
      //没有企业账号，得不到token值，返回的是null,所以支付不了
      // console.log(token);
      //4.把token存入缓存中，同时跳转回上一个页面
      wx.setStorageSync("token", token);
      wx.navigateBack({
        delta: 1  //数值表示返回上几级
      });
    } catch (error) {
      console.log(error);
    }

  }
})